<?php
/*
 * inc-pendingCompletion.php
 * Retral/CSCD494 Winter 2009
 * Eastern Washington University
 *
 * File Description:
 * 
 * Questions submitted by a user, but the admin felt needed more work - will show up here
 * Other:
 * TODO: Only show pending questions for the user that is currently logged in.
 */

/* 
 * Set up $page_name
 * This name will be compared to PAGE_NAME in NAV_URLS table (stored in session) and verify permission for given user.
 */
 
$page_name = "Pending";
$page_name = strtoupper($page_name);

$pm = $_SESSION['pagePermissions'];

// Is user logged in, and has permissions?
if (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] !="" && $_SESSION['pagePermissions'][$page_name] == 1)
{
?>
<span class="header-text">Pending for Completion</span><br>

<?php
	$conn = oci_connect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);
?>


<table border=0 width=100%>
	<tr>
		<td width=200><b><u><a href='?page=pendingCompletion&sort=question'>Question</a></u></b></td>
		<td><b><u><a href='?page=pendingCompletion&sort=request'>Request</a></u></b></td>
		<th width=100><u><a href='?page=pendingCompletion'>Date</a></u></th>
		<th width=200><u>Comment</u></th>
		<th width=25><u>Rev</u></th>
	</tr><?PHP

	$sort = " ORDER BY question.date_modified";

	if(isset($_REQUEST['sort'])) {
		if($_REQUEST['sort'] == "request")
			$sort = " ORDER BY revision_type.type_description";
		else if($_REQUEST['sort'] == "question")
			$sort = " ORDER BY question_content.question_title";
	}

	$query = '
	     SELECT question_content.question_title, change_request.question_id,
	          change_request.q_version, comments, question.date_modified,
	          revision_type.type_description 
	     FROM change_request INNER JOIN revision_type 
	     ON change_request.request_code = revision_type.request_code
        INNER JOIN question 
	     ON question.question_id=change_request.question_id 
	          AND question.q_version=change_request.q_version
	     INNER JOIN question_content 
	     ON question_content.question_content_id=question.question_content_id
		  ';

	$query .= ' WHERE revision_type.rev_type >= :RSP';
	$query .= $sort;

	$stmtList = oci_parse($conn, $query);
	oci_bind_by_name($stmtList, ':RSP', $approval->responseValue);
	if(!oci_execute($stmtList)) {
		print "<P>Could not find request list</P>";
	}

	while($request = oci_fetch_assoc($stmtList)) {

		print "<tr>\n";
		print "\t\t<td><a href='?page=question&id=".$request['QUESTION_ID'];
		print "&ver=".$request['Q_VERSION']."' name='";
		print $request['QUSETION_TITLE']."'>";
		print $request['QUESTION_TITLE']."</a></td>\n";
		print "\t\t<td>".$request['TYPE_DESCRIPTION']."</td>\n";
		print "\t\t<td>".dateFormat($request['DATE_MODIFIED'])."</td>\n";
		print "\t\t<td>";
		print $request['COMMENTS']."</td>\n";
		print "\t\t<td align='right'>".$request['Q_VERSION']."</td>\n";
		print "\t</tr>";
	}
	print "</table>";
	oci_free_statement($stmtList);
	oci_close($conn);

?>
<?php
} //end if logged in
else
{
	echo "Invalid credentials";
	echo "<META http-equiv=\"refresh\" content=\"0;URL=index.php?page=login&ld=0\">";
}	
?>
